package com.example.test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;



import java.util.List;

import com.example.test.R;
import com.example.test.bean.Course;

public class CourseAdapter extends RecyclerView.Adapter<CourseAdapter.CourseViewHolder> {

    private List<Course> courseList;
    private Context context;

    public CourseAdapter(List<Course> courseList, Context context) {
        this.courseList = courseList;
        this.context = context;
    }

    @NonNull
    @Override
    public CourseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_course, parent, false);
        return new CourseViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull CourseViewHolder holder, int position) {
        Course course = courseList.get(position);
        holder.bind(course);
    }

    @Override
    public int getItemCount() {
        return courseList.size();
    }

    public class CourseViewHolder extends RecyclerView.ViewHolder {

        private TextView tvCourseName;
        private TextView tvTeacherName;
        private TextView tvClassTime;
        private TextView tvClassLocation;

        public CourseViewHolder(@NonNull View itemView) {
            super(itemView);
            tvCourseName = itemView.findViewById(R.id.tv_course_name);
            tvTeacherName = itemView.findViewById(R.id.tv_teacher_name);
            tvClassTime = itemView.findViewById(R.id.tv_class_time);
            tvClassLocation = itemView.findViewById(R.id.tv_class_location);
        }

        public void bind(Course course) {
            tvCourseName.setText("课程名称：" +course.getCourseName());
            tvTeacherName.setText("老师：" +course.getTeacherName());
            tvClassTime.setText("上课时间：" +course.getClassTime());
            tvClassLocation.setText("地点：" +course.getClassLocation());
        }
    }
}
